<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
  <script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
  <style>
    img{
      width: 200px!important;
      height: 200px!important;
    }
  </style>
</head>
<body>
  
  <script>
    window.baseApi = '/api'
    // 页面加载完成时
    window.onload=()=>{
      getQrCode()
    }
    function getQrCode() {
      // 官方文档 https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html
      // scene_id 的最大值为 100000 这个值，严格应该由后台维护

      let myid = parseInt(Math.random()*100000);
      
      sessionStorage.setItem('myid', myid)
      let data = {
        "expire_seconds": 604800,
        "action_name": "QR_SCENE",
        "action_info": {
          "scene": { "scene_id": myid }
        }
      }
      let url = `/getQrCode`
      $.ajax({
        type: "POST",
        url,
        data: JSON.stringify(data),
        cache: false,
        async: false,
        dataType: 'json',
        contentType:'application/json',
        // dataType: ($.browser.msie) ? "text" : "xml",
        success: function (data) {
          console.log('getQrCode-成功--', data);
          // showQrCode(xmlobj)
          let url = `https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=${data.ticket}`
          // 这样前端get请求，跳转页面
          window.location.href = url;
        }
      });
    }
  </script>
</body>
</html>